// pages/complaint/complaint.js
var app = getApp();
var submitOne = false;//判断重复提交
var selectId= '';
Page({

  /**
   * 页面的初始数据
   */
  data: {
    iconUrl: '../../images/go_right-1.png',
    complaintList:[],
    selectMsg:'',
    comType: 1,//投诉类型complaint_object,1 对订单投诉 2对工单投诉 3 对产品投诉 4对工程人员投诉
    order_id: '',//如complaint_object=1必传
    work_order_id: '',//如complaint_object=2必传
    equipments_id: '',//如complaint_object=3必传
    engineers_id: '',//如complaint_object=4必传
    phone:'',//客服电话
     
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var that = this;
    var comType= options.comType;
    console.log(comType);
    that.setData({
      comType: comType
    })
    if(comType==1){
      var order_id = options.order_id;
      that.setData({
        order_id: order_id
      })
    }
    if(comType==2){
      var work_order_id = options.work_order_id;
      that.setData({
        work_order_id: work_order_id
      })
    }
    if(comType==3){
      var equipments_id = options.equipments_id;
      that.setData({
        equipments_id: equipments_id
      })
    }
    if(comType ==4){
      var engineers_id = options.engineers_id;
      that.setData({
        engineers_id: engineers_id
      })
    }
  
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
  
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    var that = this;
    var comType = that.data.comType;
    that.getComplaitList(comType);
    submitOne = false;
    that.getPhone();
  
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {
  
  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {
  
  },
  // 获取举报问题
  getComplaitList: function(comType){
    var that = this;
    app.ajax({
      url: 'User/Complaint/getTypeList',
      method: 'POST',
      data:{
        object: comType
      },
      success: function(res){
        if(res.data.code == 1000){
          var complaintList = res.data.data;
          that.setData({
            complaintList: complaintList
          })
        }
      }
    })
  },
  // 选择问题
  radioChange: function(e){
    var that = this;
       selectId = e.detail.value;
  },
  // 填写举报内容
  inputComtext: function(e){
    var that = this;
    var selectMsg = e.detail.value;
    that.setData({
      selectMsg: selectMsg
    })
  },
  // 提交
  comSubmit: function(){
    var that = this;
    var selectMsg = that.data.selectMsg;
    if (selectId == '' || selectId == null || selectId==undefined){
      app.showToast("请选择举报问题");
      return;
    }
    if (selectMsg==''){
      app.showToast("请填写举报内容");
      return;
    }
    if (submitOne){
      return;
    }
    submitOne = true;
    app.ajax({
      url: 'User/Complaint/add',
      method: 'POST',
      data:{
        complaint_type_id: selectId,
        content: selectMsg,
        complaint_object: that.data.comType,
        order_id: that.data.order_id,
        work_order_id: that.data.work_order_id,
        equipments_id: that.data.equipments_id,
        engineers_id: that.data.engineers_id,
      },
      success: function(res){
        app.showToast(res.data.message);
        submitOne = false
        if(res.data.code == 1000){
         var timer = setTimeout(function(){
           wx.navigateBack({
             delta: 1
           })
         },2000)
        }else{
         
        }
      }
    })

  },
  getPhone: function () {
    var that = this;
    // Ajax请求
    app.ajax({
      url: 'Common/Common/getSystemConfig',
      data: { key: 'company_hotline' },
      success: function (res) {
        if (res.data.code == 1000) {
          var content = res.data.data;
          that.setData({
            phone: content,
          })
        }
       
      }
    })
  },

})